package chapter1.bagqueuestack.example;

/**
 * 定容栈
 *
 * @author quanlinlin on 2018/11/28 16:35.
 * @version 1.0
 */
public class FixedCapacityStack<Item> {

    private Item[] a;
    private int    N;

    public FixedCapacityStack(int cap) {
        a = (Item[]) new Object[cap];
    }

    public boolean isEmpty() {
        return N == 0;
    }

    public boolean isFull() {
        return N == a.length;
    }

    public int size() {
        return N;
    }

    public void push(Item item) {
        a[N++] = item;
    }

    public Item pop() {
        return a[N--];
    }
}
